Next, let's take a
look at how you would define permissions
using IAM policies. To explain how Cloud IAM
authorizes an API call, I want to talk you through
what happens if you use G-Cloud to publish a
message to a Pub/Sub topic. In this example, you or G-Cloud really tries to send an API call to
pub/sub.googleapis.com. Cloud IAM will inspect
the request and identify you by the credentials
in the API request. Now that IAM has your identity, it will need to figure
out what operations you like to perform on
the Pub/Sub topic. To check if you're authorized to publish the message to
that Pub/Sub topic, IAM checks the IAM policy that is attached to
the Pub/Sub topic. If that policy has a binding that allows you
to publish the message, IAM let's to call true. An IAM policy is a list
of policy bindings. A policy binding binds a member
or an identity to a role. If you have the role
Pub/Sub publisher, you will let send messages to the Pub/Sub topic the IAM
policy is attached to. One member can have multiple policy bindings
in an IAM policy. This means you can grant more
than one role to a member. Let's take a closer look
at the type of identities that can appear in
the policy bindings. First are the human identities. If you install G-Cloud
and initialize it, you log into your
Google account and G-Cloud can perform
API calls for you. Your Google account can also be part of a group or a domain. Groups are useful if
you are setting up access policies
for your project. For example, all developers can create Cloud Run
services and read logs. You can also use a confederation if you already have an
existing identity system, for example, with Azure
Active Directory. The second Identity is
the service account, which is used by machines
on Google Cloud. Examples of Machines with service identity are
a Virtual Machine, Cloud Run Service,
a Cloud Function, or one of the services that
can call APIs for you, like Pub/Sub or Cloud tasks. The final type of identity is a special identifier, all users. Some actions like
making a request to a Cloud Run Service
are protected by IAM, but you'll need to set up
permissions to allow everyone. The second part in the
policy bindings is the role. A role is a list of permissions. An individual permission usually corresponds to an API call. There is a
permissionrun.services.creation. The two example roles on the slide are
Pub/Sub subscriber, which is a role that provides access to
consume messages from a subscription and to
attach subscriptions to a topic and Pub/Sub publisher, which provides access to
publish messages to a topic. Now, let's bring everything
together in one picture. An IAM policy is always attached to your resource
to make it effective. In this example, you're
authorized to publish messages on the
topic because one, you're a member of a
policy binding, two, the binding has the role
Pub/Sub publisher, and three, the binding is part of an IAM policy which is
attached to the topic. Another way of saying this is
that the policy binding in the IAM policy grants
you the permission to publish messages
to a specific topic. To summarize, to
authorize API calls, IAM reads the IAM policy of the resource you're trying
to perform an operation on. The IAM policy has a list of policy bindings that bind members to a role
on the resource. A role is a list of permissions and a permission generally corresponds
to an API call. IAM policies are always
attached to a resource. This is what allows access
to that resource and governs what can be
done [inaudible] and by whom and remember, whom can be a user or a service. To authorize API calls, IAM reads the IAM policy of the resource you are
trying to perform an operation on and either allows or denies that operation.